home *** CD-ROM | disk | FTP | other *** search
- /* NewLoadWB © 1995 Elaborate Bytes, Oliver Kastl
- Hides DOS devices to be seen by the Workbench */
-
-
- #include <stdarg.h>
- #include <string.h>
-
- /* Globals */
-
- struct Library *DOSBase=NULL;
- struct ExecBase *SysBase;
-
- #define TEMPLATE "ALL/S,QUIET/S,DOSDEV/M"
- #define OPT_ALL 0
- #define OPT_QUIET 1
- #define OPT_DOSDEV 2
- #define OPT_COUNT 3
-
- LONG opts[OPT_COUNT];
-
- /* Our private device list */
-
- struct List DevList;
-
- /* Protos */
-
- void RemoveDosEntry(UBYTE *name);
- void RestoreDosEntries(void);
- void RemoveDosEntries(void);
- void MyPrintf (char *format, ...);
-
- /* This is the first address of the program. We do NOT use any
- startup code to keep this thingy dingy small.
- This program will surely crash if started from Workbench.
- Is there any reason to start a LoadWB from Workbench?
- This could be a philosophical discussion during the next decade,
- I suppose.
- */
-
- long __saveds main(void)
- {
- long result;
-
- /* Yippee! The name of the command to start during the DOS devices are
- removed. The "Delay" keyword is important, otherwise we would restore
- the DOS list too early!! */
-
- UBYTE *command="C:LoadWB DELAY";
-
- SysBase = (*((struct ExecBase **)4));
-
- if(DOSBase=OpenLibrary("dos.library\0$VER: NewLoadWB 1.1 (10.04.95)",37))
- {
- struct RDArgs *ra;
- if(ra=ReadArgs(TEMPLATE,opts,NULL))
- {
- /* Initialize our private list */
-
- NewList(&DevList);
-
- if(opts[OPT_ALL])
- {
- RemoveDosEntries();
- }
- else if(opts[OPT_DOSDEV])
- {
- UBYTE **arg=(UBYTE **)opts[OPT_DOSDEV];
- while(*arg)
- {
- RemoveDosEntry(*arg++);
- }
- }
-
- if(SystemTagList(command,NULL))
- {
- result=5;
- MyPrintf("Can't start %s!\n", command);
- }
- else
- {
- result=0;
- }
- RestoreDosEntries();
- FreeArgs(ra);
- }
- else
- {
- PrintFault(IoErr(),NULL);
- result=10;
- }
- CloseLibrary(DOSBase);
- }
- else result=20;
- return result;
- }
-
-
- BOOL IsRemoveCandidate(struct DosList *dlist)
- {
- /* Check if the handler has been started already.
- If not, it is no valid candidate, as Workbench will ignore
- this entry anyway.
-
- IMPORTANT!!!
- Avoids handlers to be started by the IsFileSystem() call!
- This would cause the system to deadlock!! */
-
- if(dlist->dol_misc.dol_handler.dol_SegList)
- {
- UBYTE name[32];
- UBYTE *candidate=BADDR(dlist->dol_Name);
-
- /* Build a proper name for IsFileSystem() */
-
- /* Convert BSTR */
- memcpy(name,candidate+1,*candidate);
-
- /* Add colon */
- name[*candidate]=':';
-
- /* Terminate CSTR */
- name[*candidate+1]=0;
-
- /* Only remove Filesystems */
- /* DANGER! This sends a packet to the handler during
- LockDosList()! Shouldn't be a problem, as the handler
- has been started already... */
-
- return(IsFileSystem(name));
- }
- return(FALSE);
- }
-
-
-
- /* Remove a DOS device specified by name from the DOS device list.
- Add it in our private list for later reinsertion. */
-
- void RemoveDosEntry(UBYTE *name)
- {
- struct DosList *dlist;
- struct Node *node;
-
- dlist=LockDosList(LDF_DEVICES|LDF_WRITE);
- if(dlist=FindDosEntry(dlist, name, LDF_DEVICES))
- {
- if(IsRemoveCandidate(dlist))
- {
- if(node=AllocVec(sizeof(struct Node),MEMF_ANY))
- {
- RemDosEntry(dlist);
- node->ln_Name=(UBYTE *)dlist;
- AddHead(&DevList,node);
- }
- }
- else MyPrintf("WARNING: %s not removed!\n",name);
- }
- else MyPrintf("WARNING: %s not found!\n",name);
-
- UnLockDosList(LDF_DEVICES|LDF_WRITE);
- }
-
-
- /* Remove all DOS devices that are valid candidates from the DOS device list.
- Add them in our private list for later reinsertion. */
-
- void RemoveDosEntries(void)
- {
- struct DosList *dlist;
- struct Node *node;
-
- dlist=LockDosList(LDF_DEVICES|LDF_WRITE);
-
- /* Tricky! This works as the DOS device list is only a singly
- linked list! */
-
- while(dlist=NextDosEntry(dlist, LDF_DEVICES))
- {
- if(IsRemoveCandidate(dlist))
- {
- if(node=AllocVec(sizeof(struct Node),MEMF_ANY))
- {
- RemDosEntry(dlist);
-
- /* As I am a lazy programmer, I use the ln_Name field
- to store the entry. Good style would be the definition
- of a struct MyDevListNode bla, bla, bla... */
-
- node->ln_Name=(UBYTE *)dlist;
- AddHead(&DevList,node);
- }
- }
- }
-
- UnLockDosList(LDF_DEVICES|LDF_WRITE);
- }
-
-
- /* Scan our private list and reinsert all removed DOS devices into the
- DOS list */
-
- void RestoreDosEntries(void)
- {
- struct Node *node;
-
- LockDosList(LDF_DEVICES|LDF_WRITE);
-
- while(node=RemHead(&DevList))
- {
- AddDosEntry((struct DosList *)node->ln_Name);
- FreeVec(node);
- }
-
- UnLockDosList(LDF_DEVICES|LDF_WRITE);
- }
-
- void MyPrintf (char *format, ...)
- {
- va_list arg;
-
- va_start (arg, format);
- if(!opts[OPT_QUIET])
- VPrintf (format, arg);
- va_end (format);
- }
-